<?php

namespace Modules\Auth\Http\Controllers;
use Modules\Auth\Http\Requests\AdminRegisterRequest;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;

use Modules\Auth\Services\AdminService;
use Modules\Common\Http\Controllers\CommonController;
use Modules\Common\Transformers\CommonResource;
use Modules\Auth\Entities\Admin;

class AdminController extends CommonController
{
    private $service;
    public function __construct(AdminService $service) {
        $this->service = $service;
    }

    /**
     * Display a listing of the resource.
     * @return Renderable
     */
     public function index()
    {
        $item = $this->queryBuilder(Admin::query())->aFilters([])->aIncludes([])->page();
        return $this->success(CommonResource::collection($item) );

    }


    /**
     * Store a newly created resource in storage.
     * @param Request $request
     * @return Renderable
     */
     public function store(AdminRegisterRequest $request)
    {
        $result = $this->service->store($request);
        if(!$result){
            return $this->fail('注册失败！');
        }
        return $this->created( $result);
    }

    /**
     * Show the specified resource.
     * @param int $id
     * @return Renderable
     */
    public function show($id)
    {
        return view('auth::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @param int $id
     * @return Renderable
     */
    public function info()
    {
        $result = $this->service->info();
        return $this->success($result);
    }

    /**
     * Update the specified resource in storage.
     * @param Request $request
     * @param int $id
     * @return Renderable
     */
    public function update(Request $request, Admin $admin)
    {
        $result = $this->service->update($request,$admin);
        if(!$result){
            return $this->fail('注册失败！');
        }
        return $this->success($result);
    }

    /**
     * Remove the specified resource from storage.
     * @param int $id
     * @return Renderable
     */
    public function destroy($id)
    {
        //
    }
}
